<template>
    <div class="condition_box">
        <div class="condition_body">
            <div class="btn">
                <button @click="addCondition">添加条件{{ nodeConfig.name }}</button>
            </div>
            <div class="childs" :key="childsKey">
                <div v-for="(item, idx) in nodeConfig.children" class="child" :class="{c_child: level > 1}" :key="idx">
                    <div v-for="(it, x) in item.nodes" :key="x" class="c_child">
                        <node :nodeConfig="it" :parentNode="item"></node>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import node from './node.vue'
import { ref } from 'vue'
let props = defineProps(['nodeConfig', 'level']) //数组|对象写法都可以
let $emit = defineEmits(['addCondition','click'])
let childsKey = ref(0)
const addCondition = () => {
    props.nodeConfig.children.push({
        nodes: [
            {
                name: '添加的条件',
                type: 'CONDITION',
            }, 
        ]
    })
    console.log(props.nodeConfig);
    childsKey.value++
}
</script>

<style lang="scss" scoped>
.condition_box {
    display: flex;
}
.btn {
    position: relative;
    text-align: center;
    height: 30px;

    button {
        position: absolute;
        left: 50%;
        top: 0;
        transform: translateX(-50%);
        height: 100%;
        cursor: pointer;
        border-radius: 15px;
        outline: none;
        border: 1px solid #000;
    }
}
.childs {
    width: 100%;
    display: flex;
    flex-direction: row;
}
.child {
    /* display: flex; */
    position: relative;
    flex: 1;
    padding: 20px;
    display: flex;
    flex-flow: column;
    align-items: center;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;

    &:first-child {
        // transform: translateX(-50%);
        border: 0;

        &::after {
            content: "";
            position: absolute;
            top: 0;
            left: 50%;
            width: 50%;
            height: 100%;
            border-top: 1px solid #000;
            border-bottom: 1px solid #000;
            z-index: -1;
        }
    }
    &:last-child {
        border: 0;
        &::after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 50%;
            height: 100%;
            border-top: 1px solid #000;
            border-bottom: 1px solid #000;
            z-index: -1;
        }
    }

    &::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 0;
        width: 0;
        height: 100%;
        border-left: 1px solid #000;
        z-index: -1;
    }
}
.c_child {
    display: flex;
}
</style>
